package com.wing.cabinet.model.response;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.wing.cabinet.model.entity.CellInventorySpace;
import com.wing.cabinet.utils.ExcelExport;
import com.wing.enterprise.device.entity.Device;
import com.wing.product.model.entity.ProductDetail;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 售刀柜产品货道库存VO
 *
 * @author
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class CellInventorySpaceVO implements Comparable<CellInventorySpaceVO>{

    /**
     * ID
     */
    private Long id;

    /**
     * 创建时间
     */
    @JsonFormat(timezone = "GMT+8" , pattern = "yyyy-MM-dd HH:mm:ss" )
    private LocalDateTime createTime;

    /**
     * 创建者
     */
    private Long creator;

    /**
     * 修改者
     */
    private Long modifier;

    /**
     * 创建人
     */
    private String creatorName;

    /**
     * 修改人
     */
    private String modifierName;

    /**
     * 柜子id
     */
    private Long cabId;

    /**
     * 货道id
     */
    private Long spaceId;

    /**
     * sku id
     */
    private Long skuId;

    /**
     * 库存数量
     */
    @ExcelExport(value = "库存（包装计）",sort = 80)
    private Integer quantity;

    /**
     * skuCode
     */
    @ExcelExport(value = "物料编号",sort = 20)
    private String skuCode;

    /**
     * spaceCode
     */
    @ExcelExport(value = "货道编号",sort = 50)
    private String spaceCode;

    /**
     * cabCode
     */
    @ExcelExport(value = "柜子编号",sort = 60)
    private String cabCode;


    /**
     * sku 名称
     */
    @ExcelExport(value = "物料名称",sort = 10)
    private String skuName;

    /**
     * 状态
     */
    private CellInventorySpace.Status status;

    /**
    * 状态描述
    */
    @TableField(exist = false)
    private String statusDesc;

    public String getStatusDesc() {
        if (status!=null){
            return status.getDesc();
        }
        return null;
    }

    /**
     * sku 规格
     */
    private String skuSpec;

    /**
     * sku 图片
     */
    private String skuPic;

    /**
     * 产品名称
     */
    private String productName;

    /**
     * 产品类型名称
     */
    private String productTypeName;

    /**
     * 产品分类名称
     */
    private String productCategoryName;

    /**
     * 产品品牌
     */
    @ExcelExport(value = "品牌",sort = 40)
    private String productBrandName;

    /**
     * 产品型号
     */
    private String productModelName;

    /**
     * 适配机床
     */
    private String deviceName;

    /**
     * 市场价
     */
    private BigDecimal marketPrice;

    @ExcelExport(value = "货道容量（包装计）",sort = 130)
    private Integer quantityMax;

    @ExcelExport(value = "包装单位",sort = 90)
    private String unitName;

    /**
     * 当前库存
     */
    private Long curentStock;

    /**
     * 告警库存
     */
    private BigDecimal alarmStock;

    /**
     * 计划补货
     */
    private BigDecimal planReplenishment;

    /**
     * 建议补货
     */
    private BigDecimal proposalStock;

    /**
     * 货道数量
     */
    private int cargoLaneNum;

    private String skuCodeOld;

    @ExcelExport(value = "规格码",sort = 30)
    private String skuSpecOld;

    private Boolean showPriceFlag=true;

    /**
     * 企业自定义柜子名称
     */
    @ExcelExport(value = "柜子名称",sort = 70)
    private String cabName;

    /**
     * 企业编码
     */
    private String enterpriseCode;


    private SpareFlag spareFlag=SpareFlag.main;

    @Override
    public int compareTo(CellInventorySpaceVO o) {
        if(this.quantity>o.quantity){
            return 1;
        }else if(this.quantity==o.quantity){
            if (Integer.valueOf(this.getSpaceCode())>Integer.valueOf(o.getSpaceCode())){
                return 1;
            }else{
                return -1;
            }
        }else{
            return -1;
        }
    }

    public enum SpareFlag implements IEnum<Integer> {

        /**
         * 正常
         */
        main(0,"主物料"),
        /**
         * 告警
         */
        spare(1,"备选物料");

        private int code;
        private String desc;

        SpareFlag(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }

        @JsonCreator
        public static SpareFlag jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (SpareFlag item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }

    private String spareFlagDesc;

    public String getSpareFlagDesc(){
        if (spareFlag!=null){
            return spareFlag.getDesc();
        }
        return "";
    }

    private Integer laneCapacity;

    private Integer remainingTime;

    private ProductDetail.LifeUnit lifeUnit;

    private StringBuffer lifeUnitDesc;

    public String getLifeUnitDesc(){
        if (this.lifeUnit!=null){
            return this.lifeUnit.getDesc();
        }
        return "";
    }

    private String mainCabCode;

    private Long packId;
    @ExcelExport(value = "包装规格",sort = 100)
    private String packName;

    private Integer quantityPackUnit;
    @ExcelExport(value = "库存（基础单位计）",sort = 110)
    private Integer quantityPack;
    @ExcelExport(value = "基础单位",sort = 120)
    private String basicsUnitName;
    @ExcelExport(value = "主柜编号",sort = 51)
    private String belongCabinet;

}
